package com.kvest.gps_tracker.activity;

import com.kvest.gps_tracker.R;
import com.kvest.gps_tracker.core.Settings;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class SettingsActivity extends Activity
{
	private EditText extraordinaryDisplacement;
	private EditText extraordinaryRotate;
	private EditText zeroSpeedInterval;
	private EditText lowSpeedInterval;
	private EditText hightSpeedInterval;
	
	@Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        
        setComponents();
    }
	
	private void setComponents() 
	{
		Settings settings = Settings.getSettings();
		
		extraordinaryDisplacement = (EditText)findViewById(R.id.edt_extraordinary_displacement);
		extraordinaryDisplacement.setText(Integer.toString(settings.getExtraordinaryDisplacement()));
			
		extraordinaryRotate = (EditText)findViewById(R.id.edt_extraordinary_rotate);
		extraordinaryRotate.setText(Integer.toString(settings.getExtraordinaryRotate()));
		
		zeroSpeedInterval = (EditText)findViewById(R.id.edt_zero_speed_interval);
		zeroSpeedInterval.setText(Integer.toString(settings.getZeroSpeedInterval()));
		
		lowSpeedInterval = (EditText)findViewById(R.id.edt_low_speed_interval);
		lowSpeedInterval.setText(Integer.toString(settings.getLowSpeedInterval()));
		
		hightSpeedInterval = (EditText)findViewById(R.id.edt_hight_speed_interval);
		hightSpeedInterval.setText(Integer.toString(settings.getHightSpeedInterval()));
	}

	private void save()
	{
		Settings settings = Settings.getSettings();
		settings.setExtraordinaryDisplacement(Integer.parseInt(extraordinaryDisplacement.getText().toString()));
		settings.setExtraordinaryRotate(Integer.parseInt(extraordinaryRotate.getText().toString()));
		settings.setZeroSpeedInterval(Integer.parseInt(zeroSpeedInterval.getText().toString()));
		settings.setLowSpeedInterval(Integer.parseInt(lowSpeedInterval.getText().toString()));
        settings.setHightSpeedInterval(Integer.parseInt(hightSpeedInterval.getText().toString()));
        
        settings.save();
	}
	
	public void onSave(View view)
	{
		save();
		
		finish();
	}
	
	public void onCancel(View view)
	{
		finish();
	}
}
